<template><div><p><strong>1 引入依赖</strong></p>
<div class="language-xml ext-xml line-numbers-mode"><pre v-pre class="language-xml"><code><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">></span></span>org.springframework.boot<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">></span></span>spring-boot-starter-security<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">></span></span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>启动项目，访问任何路径都将进入SpringSecurity自带的登录页面。</p>
<p><img src="https://s2.loli.net/2022/05/09/Izyvcanrles7GVS.png" alt="image-20220509142318908"></p>
<p><strong>2 自定义认证</strong></p>
<p>实现UserDetailsService接口中的loadUserByUsername方法。</p>
<p><img src="https://s2.loli.net/2022/05/09/WeHYoF7ZNxwfcIv.png" alt="image-20220509143012485"></p>
<p>loadUserByUsername返回UserDetails接口对象。</p>
<p><img src="https://s2.loli.net/2022/05/09/cqa79zxvKYLkeIN.png" alt="image-20220509143135652"></p>
<ul>
<li>getAuthorities：获取所有权限。</li>
<li>getPassword：获取密码。</li>
<li>getUserName：获取用户名。</li>
<li>isAccountNotExpired：用户是否过期。</li>
<li>isAccountNotLocked：用户是否被锁定。</li>
<li>isCredentialsNotExpired：用户密码是否过期。</li>
<li>isEnabled：账户是否可用。</li>
</ul>
<p>UserDetails实现类User。</p>
</div></template>
